﻿Namespace Istatistik.Faaliyet
	Friend Module Functions

		Sub Kaydet(Token As Token, yil As Integer, ay As Integer, ad As String, deger As Double)
			Token.ExecSQL("delete from ssd..istfaaliyet where yil = @yil and ay = @ay and ad = @ad", yil, ay, ad)
			Token.Save("ssd.dbo.istfaaliyet", "yil,ay,ad,deger", yil, ay, ad, deger)
		End Sub

		Function Oku(Token As Token, yil As Integer, ay As Integer, ad As String) As Recordset
			Return Token.OpenSQL("select deger from ssd..istfaaliyet where yil = @yil and ay = @ay and ad = @ad", yil, ay, ad)
		End Function

		Function Sum(Token As Token, yil As Integer, ay As Integer, ad As String, type As String) As Recordset
			Q("select sum(deger) from ssd..istfaaliyet where ad like '" & ad & "%'")
			Select Case type
				Case 0, 1, 2
					Dim opr As String = ""
					Select Case type
						Case 0 : opr = "="
						Case 1 : opr = "<="
						Case 2 : opr = "<"
					End Select
					Q("and yil * 100 + ay " & opr & " " & (yil * 100 + ay))
				Case 3
					Q("and yil * 100 + ay = " & Format(CDate(Trim(yil) & "/" & Trim(ay) & "/01").AddMonths(-1), "yyyyMM"))
			End Select
			Return Token.OpenSQL("*")
		End Function

	End Module
End Namespace